package com.qdc.datacenters.controller;

import com.qdc.datacenters.annotation.Log;
import com.qdc.datacenters.domain.ResponseResult;
import com.qdc.datacenters.domain.query.login.LoginQuery;
import com.qdc.datacenters.domain.vo.login.LoginUserVo;
import com.qdc.datacenters.enums.BusinessTypeEnum;
import com.qdc.datacenters.enums.OperatorTypeEnum;
import com.qdc.datacenters.service.ILoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author danmo
 * @date 2024-02-21 15:08
 **/
@Tag(name = "授权登录")
@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    private ILoginService iLoginService;

    @Log(title = "系统登陆",businessType = BusinessTypeEnum.LOGIN,operatorType = OperatorTypeEnum.MANAGE)
    @Operation(summary = "系统登陆", method = "POST")
    @PostMapping("/login")
    public ResponseResult<LoginUserVo> login(@Validated @RequestBody LoginQuery query) {
        return ResponseResult.success(iLoginService.login(query));
    }

    @Log(title = "系统登出",businessType = BusinessTypeEnum.LOGOUT,operatorType = OperatorTypeEnum.MANAGE)
    @Operation(summary = "系统登出", method = "GET")
    @GetMapping("/logout")
    public ResponseResult logout() {
        iLoginService.logout();
        return ResponseResult.success();
    }
}
